package com.visikard.item;

import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

import com.visikard.application.Constant;
import com.visikard.widget.expandedlistview.BaseExpandableListItem;

public class ItemTransactionProduct extends BaseExpandableListItem implements Parcelable {

	String kardName;
	long userId;
	long merchantId;
	long dateTime;
	int isGiftSpecial;
	long purchaseTransactionId;
	String redemptionValue;
	String kardImage;
	long redeemedTransactionId;
	String remainingValue;
	String dateTimeWithTimezone;
	int iscoupon;
	String imageGiftKard;
	String username;
	String paymentMethod; // not found in new arm
	String redeemptionCode;
	String originalAmount;
	String address;
	int redeemedCount; // not found int new arm
	String kardNumber; // not found int new arm
	String status; // not found int new arm
	int requiredBuy; // not found int new arm
	int redeemTime;

	// New Arm
	private long staffId;
	private long storeId;
	private int campaignType;
	private String campaignDetailLabel = "";
	private String campaignDetail = "";
	private int categoryCard;
	private long couponID;
	private long idCampaign;
	private String storeName = "";

	// UI
	public static final int DEFAULT_COLLAPSED_HEIGHT = 161;

	public ItemTransactionProduct() {
		super(DEFAULT_COLLAPSED_HEIGHT);
	}

	public ItemTransactionProduct(JSONObject job) {
		super(DEFAULT_COLLAPSED_HEIGHT);

		if (job == null)
			return;

		kardName = job.optString("kardName", "");
		if (kardName == null || kardName.equals("null"))
			kardName = "";

		userId = job.optLong("userId", -1);

		merchantId = job.optLong("merchantId", -1);

		dateTime = job.optLong("dateTime", 0);

		isGiftSpecial = job.optInt("isGiftSpecial", 0);

		purchaseTransactionId = job.optLong("purchaseTransactionId", -1);

		redemptionValue = job.optString("redemptionValue", "0.00");
		if (redemptionValue == null || redemptionValue.equals("null"))
			redemptionValue = "0.00";

		kardImage = job.optString("kardImage", "");
		if (kardImage == null || kardImage.equals("null"))
			kardImage = "";

		redeemedTransactionId = job.optLong("redeemedTransactionId", -1);

		remainingValue = job.optString("remainingValue", "0.00");
		if (remainingValue == null || remainingValue.equals("null"))
			remainingValue = "0.00";

		dateTimeWithTimezone = job.optString("dateTimeWithTimezone", "");
		if (dateTimeWithTimezone == null || dateTimeWithTimezone.equals("null"))
			dateTimeWithTimezone = "";

		iscoupon = job.optInt("iscoupon", 0);

		imageGiftKard = job.optString("imageGiftKard", "");
		if (imageGiftKard == null || imageGiftKard.equals("null"))
			imageGiftKard = "";

		username = job.optString("username", "");
		if (username == null || username.equals("null"))
			username = "";

		paymentMethod = job.optString("paymentMethod", "");
		if (paymentMethod == null || paymentMethod.equals("null"))
			paymentMethod = "";

		redeemptionCode = job.optString("redeemCode", "");
		if (redeemptionCode == null || redeemptionCode.equals("null"))
			redeemptionCode = "";

		originalAmount = job.optString("originalAmount", "0.00");
		if (originalAmount == null || originalAmount.equals("null"))
			originalAmount = "0.00";

		address = job.optString("address", "");
		if (address == null || address.equals("null"))
			address = "";

		redeemedCount = job.optInt("redeemedCount", 0);

		kardNumber = job.optString("kardNumber", "");
		if (kardNumber == null || kardNumber.equals("null"))
			kardNumber = "";

		status = job.optString("status", "");
		if (status == null || status.equals("null"))
			status = "";

		// new api returns
		requiredBuy = job.optInt("requireBuy", 0);
		redeemTime = job.optInt("redeemTime", 0);

		staffId = job.optLong("staffId", Constant.INVALID_ID);
		storeId = job.optLong("storeId", Constant.INVALID_ID);
		campaignType = job.optInt("campaignType", -1);
		campaignDetailLabel = job.optString("campaignDetailLabel", "");
		campaignDetail = job.optString("campaignDetail", "");
		categoryCard = job.optInt("categoryCard", -1);
		couponID = job.optLong("couponID", Constant.INVALID_ID);
		idCampaign = job.optLong("idCampaign", Constant.INVALID_ID);
		storeName = job.optString("storeName", "");
	}

	// constructor used for pacerlable
	protected ItemTransactionProduct(Parcel src) {
		super(DEFAULT_COLLAPSED_HEIGHT);

		kardName = src.readString();
		userId = src.readLong();
		merchantId = src.readLong();
		dateTime = src.readLong();
		isGiftSpecial = src.readInt();
		purchaseTransactionId = src.readLong();
		redemptionValue = src.readString();
		kardImage = src.readString();
		redeemedTransactionId = src.readLong();
		remainingValue = src.readString();
		dateTimeWithTimezone = src.readString();
		iscoupon = src.readInt();
		imageGiftKard = src.readString();
		username = src.readString();
		paymentMethod = src.readString();
		redeemptionCode = src.readString();
		originalAmount = src.readString();
		address = src.readString();
		redeemedCount = src.readInt();
		kardNumber = src.readString();
		status = src.readString();
		requiredBuy = src.readInt();
		redeemTime = src.readInt();

		// new arm
		staffId = src.readLong();
		storeId = src.readLong();
		campaignType = src.readInt();
		campaignDetailLabel = src.readString();
		campaignDetail = src.readString();
		categoryCard = src.readInt();
		couponID = src.readLong();
		idCampaign = src.readLong();
		storeName = src.readString();
	}

	@Override
	public void writeToParcel(Parcel target, int arg1) {
		target.writeString(kardName);
		target.writeLong(userId);
		target.writeLong(merchantId);
		target.writeLong(dateTime);
		target.writeInt(isGiftSpecial);
		target.writeLong(purchaseTransactionId);
		target.writeString(redemptionValue);
		target.writeString(kardImage);
		target.writeLong(redeemedTransactionId);
		target.writeString(remainingValue);
		target.writeString(dateTimeWithTimezone);
		target.writeInt(iscoupon);
		target.writeString(imageGiftKard);
		target.writeString(username);
		target.writeString(paymentMethod);
		target.writeString(redeemptionCode);
		target.writeString(originalAmount);
		target.writeString(address);
		target.writeInt(redeemedCount);
		target.writeString(kardNumber);
		target.writeString(status);
		target.writeInt(redeemTime);
		target.writeInt(requiredBuy);

		// new arm
		target.writeLong(staffId);
		target.writeLong(storeId);
		target.writeInt(campaignType);
		target.writeString(campaignDetailLabel);
		target.writeString(campaignDetail);
		target.writeInt(categoryCard);
		target.writeLong(couponID);
		target.writeLong(idCampaign);
		target.writeString(storeName);
	}

	public static final Parcelable.Creator<ItemTransactionProduct> CREATOR = new Creator<ItemTransactionProduct>() {
		@Override
		public ItemTransactionProduct createFromParcel(Parcel source) {
			return new ItemTransactionProduct(source);
		}

		@Override
		public ItemTransactionProduct[] newArray(int size) {
			return new ItemTransactionProduct[size];
		}
	};

	public String getKardName() {
		return kardName;
	}

	public long getUserId() {
		return userId;
	}

	public long getMerchantId() {
		return merchantId;
	}

	public long getDateTime() {
		return dateTime;
	}

	public int getIsGiftSpecial() {
		return isGiftSpecial;
	}

	public long getPurchaseTransactionId() {
		return purchaseTransactionId;
	}

	public String getRedemptionValue() {
		return redemptionValue;
	}

	public String getKardImage() {
		return kardImage;
	}

	public long getRedeemedTransactionId() {
		return redeemedTransactionId;
	}

	public String getRemainingValue() {
		return remainingValue;
	}

	public String getDateTimeWithTimezone() {
		return dateTimeWithTimezone;
	}

	public int getIscoupon() {
		return iscoupon;
	}

	public String getImageGiftKard() {
		return imageGiftKard;
	}

	public String getUsername() {
		return username;
	}

	public String getPaymentMethod() {
		return paymentMethod;
	}

	public void setPaymentMethod(String paymentMethod) {
		this.paymentMethod = paymentMethod;
	}

	public String getRedeemptionCode() {
		return redeemptionCode;
	}

	public void setRedeemptionCode(String redeemptionCode) {
		this.redeemptionCode = redeemptionCode;
	}

	public String getOriginalAmount() {
		return originalAmount;
	}

	public double getOriginalAmountNumber() {
		try {
			// String strValue = purchase_value.split("$")[0];
			String strValue = originalAmount.substring(1, originalAmount.length());
if (strValue.isEmpty()) {
				strValue = originalAmount;
			}
			return Double.parseDouble(strValue);
		}
		catch (Exception e) {
			return 0;
		}
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public int getRedeemedCount() {
		return redeemedCount;
	}

	public void setRedeemedCount(int redeemedCount) {
		this.redeemedCount = redeemedCount;
	}

	public String getKardNumber() {
		return kardNumber;
	}

	public void setKardNumber(String kardNumber) {
		this.kardNumber = kardNumber;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getRequiredBuy() {
		return requiredBuy;
	}

	public void setRequiredBuy(int requiredBuy) {
		this.requiredBuy = requiredBuy;
	}

	public int getRedeemTime() {
		return redeemTime;
	}

	public void setRedeemTime(int redeemTime) {
		this.redeemTime = redeemTime;
	}

	public long getStaffId() {
		return staffId;
	}

	public void setStaffId(long staffId) {
		this.staffId = staffId;
	}

	public long getStoreId() {
		return storeId;
	}

	public void setStoreId(long storeId) {
		this.storeId = storeId;
	}

	public int getCampaignType() {
		return campaignType;
	}

	public void setCampaignType(int campaignType) {
		this.campaignType = campaignType;
	}

	public String getCampaignDetailLabel() {
		return campaignDetailLabel;
	}

	public void setCampaignDetailLabel(String campaignDetailLabel) {
		this.campaignDetailLabel = campaignDetailLabel;
	}

	public String getCampaignDetail() {
		return campaignDetail;
	}

	public void setCampaignDetail(String campaignDetail) {
		this.campaignDetail = campaignDetail;
	}

	public int getCategoryCard() {
		return categoryCard;
	}

	public void setCategoryCard(int categoryCard) {
		this.categoryCard = categoryCard;
	}

	public long getCouponID() {
		return couponID;
	}

	public void setCouponID(long couponID) {
		this.couponID = couponID;
	}

	public long getIdCampaign() {
		return idCampaign;
	}

	public void setIdCampaign(long idCampaign) {
		this.idCampaign = idCampaign;
	}

	public String getStoreName() {
		return storeName;
	}

	public void setStoreName(String storeName) {
		this.storeName = storeName;
	}
}
